package adv329;

import adv327.Sex;
import adv327.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class ListSort {
    public static void main(String[] args) {
        List<Student> l2=new ArrayList<>();
        l2.add(new Student("王智睿",18, Sex.男));
        l2.add(new Student("胡汪洋",27, Sex.男));
        l2.add(new Student("yiwenlong",22, Sex.男));
        l2.add(new Student("赵俊杰",17, Sex.男));
        Collections.sort(l2);
        System.out.println("默认排序：");
        for(Student s:l2){
            System.out.println(s);
        }
        System.out.println("按照name排序：");
        //指定比较器！
        Collections.sort(l2,new MyCom());
        for(Student s:l2){
            System.out.println(s);
        }
    }
}
class MyCom implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.getName().compareTo(o2.getName());
    }
}